package com.originskyseed.platform.count.service.impl;

import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.stereotype.Component;

import com.originskyseed.platform.core.base.BasePage;
import com.originskyseed.platform.core.util.bean.PrimaryKeyGeneratorUtil;
import com.originskyseed.platform.count.mapper.FinancialManageRelateAnnexMapper;
import com.originskyseed.platform.count.model.FinancialManageRelateAnnex;
import com.originskyseed.platform.count.service.IFinancialManageRelateAnnexService;

/**
 * 财务管理附件信息Service接口实现类（OSI_FINANCIAL_MANAGE_RELATE_ANNEX）
 *
 * @author wlj
 */
@DubboService
@Component("financialManageRelateAnnexService")
public class FinancialManageRelateAnnexServiceImpl implements IFinancialManageRelateAnnexService {

	@Resource
	private FinancialManageRelateAnnexMapper financialManageRelateAnnexMapper;

	/**
	 * 删除记录
	 *
	 * @param id
	 * @return
	 * @throws Exception
	 */
	@Override
	public int deleteByPrimaryKey(String id) throws Exception {
		return this.financialManageRelateAnnexMapper.deleteByPrimaryKey(id);
	}

	/**
	 * 批量删除记录
	 *
	 * @param ids
	 * @return
	 * @throws Exception
	 */
	@Override
	public int deleteByPrimaryKeys(List<String> ids) throws Exception {
		return this.financialManageRelateAnnexMapper.deleteByPrimaryKeys(ids);
	}

	/**
	 * 插入记录
	 *
	 * @param record
	 * @return
	 * @throws Exception
	 */
	@Override
	public int insert(FinancialManageRelateAnnex record) throws Exception {
		if (StringUtils.isBlank(record.getId())) {
			record.setId(PrimaryKeyGeneratorUtil.getInstance().getRandomKey());
		}
		record.setCreateTime(new Date());
		return this.financialManageRelateAnnexMapper.insert(record);
	}

	/**
	 * 插入记录（仅非空值字段）
	 *
	 * @param record
	 * @return
	 * @throws Exception
	 */
	@Override
	public int insertSelective(FinancialManageRelateAnnex record) throws Exception {
		if (StringUtils.isBlank(record.getId())) {
			record.setId(PrimaryKeyGeneratorUtil.getInstance().getRandomKey());
		}
		record.setCreateTime(new Date());
		return this.financialManageRelateAnnexMapper.insertSelective(record);
	}

	/**
	 * 更新记录
	 *
	 * @param record
	 * @return
	 * @throws Exception
	 */
	@Override
	public int updateByPrimaryKey(FinancialManageRelateAnnex record) throws Exception {
		record.setUpdateTime(new Date());
		return this.financialManageRelateAnnexMapper.updateByPrimaryKey(record);
	}

	/**
	 * 更新记录（仅非空值字段）
	 *
	 * @param record
	 * @return
	 * @throws Exception
	 */
	@Override
	public int updateByPrimaryKeySelective(FinancialManageRelateAnnex record) throws Exception {
		record.setUpdateTime(new Date());
		return this.financialManageRelateAnnexMapper.updateByPrimaryKeySelective(record);
	}

	/**
	 * 查询记录
	 *
	 * @param id
	 * @return
	 * @throws Exception
	 */
	@Override
	public FinancialManageRelateAnnex selectByPrimaryKey(String id) throws Exception {
		return this.financialManageRelateAnnexMapper.selectByPrimaryKey(id);
	}

	/**
	 * 查询记录
	 *
	 * @param id
	 * @return
	 * @throws Exception
	 */
	@Override
	public FinancialManageRelateAnnex selectByFinancialManageId(String id) throws Exception {
		return this.financialManageRelateAnnexMapper.selectByFinancialManageId(id);
	}

	/**
	 * 查询列表
	 *
	 * @param record
	 * @return
	 * @throws Exception
	 */
	@Override
	public List<FinancialManageRelateAnnex> selectList(FinancialManageRelateAnnex record) throws Exception {
		return this.financialManageRelateAnnexMapper.selectList(record);
	}

	/**
	 * 分页查询列表
	 *
	 * @param params
	 * @param page
	 * @return
	 * @throws Exception
	 */
	@Override
	public BasePage<FinancialManageRelateAnnex> selectListByPage(Map<String, Object> params, BasePage<FinancialManageRelateAnnex> page) throws Exception {
		params.put("page", page);
		List<FinancialManageRelateAnnex> list = this.financialManageRelateAnnexMapper.selectListByPage(params);
		page.setResults(list);
		return page;
	}

}
